home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / vi.arc / VI.DOC < prev   
Text File  |  1987-05-28  |  17KB  |  849 lines

  1.           ------------------------------------------------------------
  2.  
  3.  
  4.                                  ===== VI =====
  5.  
  6.  
  7.           ------------------------------------------------------------
  8.  
  9.  
  10.  
  11.                VI is a screen text editor written for the IBM  PC.  It
  12.  
  13.           has been given the same name  as the  screen editor  for the
  14.  
  15.           Berkeley  Unix  operating system.   This is  no coincidence:
  16.  
  17.           with a few exceptions, this editor is a  subset of  the lat-
  18.  
  19.           ter.   Users  familiar  with  Unix can  skip to  the command
  20.  
  21.           summary at the end of this file.
  22.  
  23.  
  24.                This editor requires an  80-column display,  MS-DOS 1.1
  25.  
  26.           or better, and 128K of memory.
  27.  
  28.  
  29.  
  30.           Getting started
  31.  
  32.           ------- -------
  33.  
  34.  
  35.                To edit an existing file, type
  36.  
  37.  
  38.                     vi name
  39.  
  40.  
  41.           as a DOS command.  The first few lines of the file will then
  42.  
  43.           appear on the screen,  and you  may use  any of  the editing
  44.  
  45.           commands to modify it.  For example:
  46.  
  47.  
  48.                dw        delete a word
  49.  
  50.                de        delete a word, leaving punctuation
  51.  
  52.                dd        delete a line
  53.  
  54.                3dd       delete three lines
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.                itextEND  insert text
  68.  
  69.                /string   search for string
  70.  
  71.                xp        transpose characters (actually two commands)
  72.  
  73.  
  74.           In addition, all of the keys on  the numeric  keypad perform
  75.  
  76.           as labeled.  When you are finished  editing, type  :w<cr> to
  77.  
  78.           update the copy of the file residing on disk, and  then type
  79.  
  80.           :q<cr> to quit VI.  The command  :wq<cr> combines  the above
  81.  
  82.           two "colon" commands into a single command.
  83.  
  84.  
  85.                If you had not modified the file  in the  above editing
  86.  
  87.           session, the ":w" would have been superfluous and  you could
  88.  
  89.           quit with just ":q".  If you had made  changes, but  did not
  90.  
  91.           want to save them, you should  also omit  the ":w",  but use
  92.  
  93.           ":q!" to quit so as to avoid an error message.
  94.  
  95.  
  96.                If the file named in the DOS command "vi name" does not
  97.  
  98.           exist, VI starts with an empty file, into which text  can be
  99.  
  100.           inserted.  This is how VI can be used to create a file.
  101.  
  102.  
  103.  
  104.           VI States
  105.  
  106.           -- ------
  107.  
  108.  
  109.                VI has three states, all of which occur in at least one
  110.  
  111.           of the above commands.  They are,
  112.  
  113.  
  114.           o    Command  mode.   This  is  the normal  and initial
  115.  
  116.                state.  All commands return here after completion.
  117.  
  118.  
  119.           o    Insert mode.  Characters typed in insert mode are,
  120.  
  121.                as the name implies, copied into the  file instead
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.                of interpreted  as commands.   The "End"  and "In-
  134.  
  135.                sert"  keys return  VI to  command mode  (and vice
  136.  
  137.                versa for "Insert").  The "Escape" key works as in
  138.  
  139.                DOS (as opposed to  Unix):  it  deletes characters
  140.  
  141.                typed so far in  the current  line.  In  this mode
  142.  
  143.                the cursor is larger than in command mode.
  144.  
  145.  
  146.           o    Last line mode.  In this mode the editor  is read-
  147.  
  148.                ing text for a ":" command or a "/" or "?" search.
  149.  
  150.                The text ends with <cr>; "Escape" deletes the text
  151.  
  152.                but not the ":", "/", or "?"  (unless there  is no
  153.  
  154.                text).
  155.  
  156.  
  157.  
  158.           Counts Before VI Commands
  159.  
  160.           ------ ------ -- --------
  161.  
  162.  
  163.                Many  VI  commands can  be preceded  by a  number.  The
  164.  
  165.           effect of this number is usually to repeat the effect of the
  166.  
  167.           command.   Sometimes,  however, it  has other  meanings.  In
  168.  
  169.           many cases it is ignored.
  170.  
  171.  
  172.  
  173.           The Screen
  174.  
  175.           --- ------
  176.  
  177.  
  178.                The first 24 lines of  the screen  are used  to display
  179.  
  180.           the file; the last line is used for last  line mode  and for
  181.  
  182.           messages.  Lines past the end  of the  file appear  as lines
  183.  
  184.           consisting of a single  tilde ("~").   Tabs are  expanded to
  185.  
  186.           columns 9, 17, 25, ..., 73, 1, ....  Long lines  are wrapped
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.           around,  so  that  they  may  take up  several lines  of the
  200.  
  201.           screen.  "@" lines indicate that the next  line is  too long
  202.  
  203.           to fit on the remainder of the screen.  The user  should not
  204.  
  205.           create lines too long to fit on a  screen, although  VI will
  206.  
  207.           not stop him from trying.
  208.  
  209.  
  210.                In case DOS (or a program bug) scrambles the screen, ^L
  211.  
  212.           will restore it to what it should be.
  213.  
  214.  
  215.                If a command causes the cursor to move to a part of the
  216.  
  217.           file which is not currently displayed on the screen, VI will
  218.  
  219.           automatically scroll as necessary.  VI also has  commands to
  220.  
  221.           explicitly request scrolling:
  222.  
  223.  
  224.  
  225.                ^F or PgDn  Move the screen Forward one screenful,
  226.  
  227.                            keeping the last two lines of  the old
  228.  
  229.                            screen as the first  two lines  of the
  230.  
  231.                            new.
  232.  
  233.                ^B or PgUp  Move Backwards one screenful.
  234.  
  235.                ^D          Move Down 1/2 screen.
  236.  
  237.                ^U          Move Up 1/2 screen.
  238.  
  239.  
  240.  
  241.           Motion Commands
  242.  
  243.           ------ --------
  244.  
  245.  
  246.                The arrows on  the numeric  keypad perform  as labeled.
  247.  
  248.           Also, VI has a rich assortment of other commands to move the
  249.  
  250.           cursor.  These are:
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.                + or <cr>   Move the cursor to the  first nonblank
  266.  
  267.                            character  of  the  next  line  in the
  268.  
  269.                            file.  (All motions referring to lines
  270.  
  271.                            put the cursor  on the  first nonblank
  272.  
  273.                            character of that line.)
  274.  
  275.                -           Move to the previous line.
  276.  
  277.                $           Move to the end of the current line.
  278.  
  279.                0           Move to the beginning of the line.
  280.  
  281.  
  282.                fx          Find the next occurrence of  the given
  283.  
  284.                            character.  The  search is  limited to
  285.  
  286.                            the current line.
  287.  
  288.                Fx          Same as fx, backwards.
  289.  
  290.                ;           Repeat the previous f or F.
  291.  
  292.  
  293.                /string<cr> Search for the next occurrence  of the
  294.  
  295.                            given string.   This search  starts at
  296.  
  297.                            the  current  position,  but  may wrap
  298.  
  299.                            around the beginning of the file.
  300.  
  301.                ?string<cr> Same as "/", searching backwards.
  302.  
  303.                n           Repeat last "/" or "?" search.
  304.  
  305.                N           Same  as "n",  in the  opposite direc-
  306.  
  307.                            tion.
  308.  
  309.                H or Home   Move the cursor to  the first  line of
  310.  
  311.                            the screen.
  312.  
  313.                M           The middle line of the screen.
  314.  
  315.                L or End    Move to the last line of the screen.
  316.  
  317.                nG          Move to the nth line of the file.
  318.  
  319.                G           Move to the last line.
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.                %           Move  to  the   matching  parenthesis,
  332.  
  333.                            bracket, or brace.
  334.  
  335.  
  336.  
  337.           The Delete Operator
  338.  
  339.           --- ------ --------
  340.  
  341.  
  342.                If one of the above motions is  preceded by  the letter
  343.  
  344.           "d", then VI will delete the text, from the old  position to
  345.  
  346.           the new position.  This called an operator because  it chan-
  347.  
  348.           ges the effect of the ensuing  motion command.   The repeti-
  349.  
  350.           tion  count  for the  motion command  may either  precede or
  351.  
  352.           follow the "d"; the effect is the same.
  353.  
  354.  
  355.                Also, "d" may be doubled (i.e. dd or 7dd) to delete one
  356.  
  357.           or several lines.  If D is  capitalized, it  deletes through
  358.  
  359.           the end of the line.
  360.  
  361.  
  362.                Other operators are  "c" (change)  and "y"  (yank), de-
  363.  
  364.           scribed later.
  365.  
  366.  
  367.  
  368.           Other Deletion Commands
  369.  
  370.           ----- -------- --------
  371.  
  372.  
  373.                x or Delete Functions the same as  dSpace; deletes
  374.  
  375.                            one character.
  376.  
  377.                X           Deletes backwards one  character; same
  378.  
  379.                            as dh.
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.           Insert Mode
  398.  
  399.           ------ ----
  400.  
  401.  
  402.                A number  of commands  place the  user in  insert mode.
  403.  
  404.           They are:
  405.  
  406.  
  407.  
  408.                i    Enter insert mode, inserting text  before the
  409.  
  410.                     current character.
  411.  
  412.                a    Insert after the current character.
  413.  
  414.                A    Insert after end of line.
  415.  
  416.                o    Open a new  line after  the current  line and
  417.  
  418.                     enter insert mode.
  419.  
  420.                O    Open before current line.
  421.  
  422.                c<motion>, cc, C   "c" is an operator,  similar to
  423.  
  424.                     "d".  It deletes text  and leaves  the editor
  425.  
  426.                     in  insert mode.   For example,  "cw" changes
  427.  
  428.                     the current word; "cc", the current line.
  429.  
  430.  
  431.  
  432.           Other Modification Commands
  433.  
  434.           ----- ------------ --------
  435.  
  436.  
  437.  
  438.                rx   Replaces the current character with the char-
  439.  
  440.                     acter  x.
  441.  
  442.                J    Joins  two  lines;  i.e.  concatenates  them,
  443.  
  444.                     adding a space between them.
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.           Undo and Repeat
  464.  
  465.           ---- --- ------
  466.  
  467.  
  468.                In case of  a mistake,  the "u"  command will  undo the
  469.  
  470.           effect of the last  command which  modified the  file.  Only
  471.  
  472.           the most recent change can be undone in this way.
  473.  
  474.  
  475.                The  dot  command  (".") will  repeat the  last command
  476.  
  477.           which changed the file.
  478.  
  479.  
  480.  
  481.           Moving Text
  482.  
  483.           ------ ----
  484.  
  485.  
  486.                To  move part  of a  file, one  uses the  operations of
  487.  
  488.           yanking and putting.  Yanking consists of copying part  of a
  489.  
  490.           file into a special buffer; putting copies that  buffer into
  491.  
  492.           another part of the file.
  493.  
  494.  
  495.                To yank text, use the "y"  operator (y<motion>,  yy, or
  496.  
  497.           Y) in the  same manner  as the  delete or  change operators.
  498.  
  499.           Then move the cursor  and use  the put  command (p)  or put-
  500.  
  501.           before command (P) to put the text elsewhere.  For example,
  502.  
  503.  
  504.                                    5G yy 9G p
  505.  
  506.  
  507.           places another copy of the fifth line of the file  after the
  508.  
  509.           ninth line.
  510.  
  511.  
  512.                The delete and change operators  also save  the deleted
  513.  
  514.           text in a yank buffer.  Thus the command "xp"  (actually two
  515.  
  516.           commands) exchanges two characters by deleting the first and
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.           reinserting it after the second.
  530.  
  531.  
  532.                In addition to the default yank buffer, VI has 26 other
  533.  
  534.           yank buffers, tagged by (lower-case)  letters of  the alpha-
  535.  
  536.           bet.  To let a yank, put, delete, or change  command command
  537.  
  538.           refer to one of these buffers, precede the command  with the
  539.  
  540.           quote character and the letter of the buffer.
  541.  
  542.  
  543.                Transferring text between files can be  done in  one of
  544.  
  545.           several ways.  First, the command
  546.  
  547.  
  548.                               :r name
  549.  
  550.  
  551.           reads the named file  into the  current file,  following the
  552.  
  553.           current line.
  554.  
  555.  
  556.                The reverse of this operation is the command,
  557.  
  558.  
  559.                               :p name
  560.  
  561.  
  562.           which puts the buffer  into a  file of  the given  name, de-
  563.  
  564.           stroying  the file's  previous contents,  if any.   "x:p and
  565.  
  566.           :"xp are also valid; both do the same as :p with buffer x.
  567.  
  568.  
  569.                The last wat of transferring text  between files  is to
  570.  
  571.           yank one or more pieces of text, switch the main file via
  572.  
  573.  
  574.                               :e name
  575.  
  576.                            or :e! name
  577.  
  578.  
  579.           and then put the text into the new main file.
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.           Helpful Hints
  596.  
  597.           ------- -----
  598.  
  599.  
  600.                In addition to deleting the current line in  insert and
  601.  
  602.           last line  modes, the  Escape key  can be  used to  delete a
  603.  
  604.           partially  complete command.   It also  momentarily enlarges
  605.  
  606.           the cursor.  This makes it easier to see--it is easy to lose
  607.  
  608.           the cursor after a locate operation.
  609.  
  610.  
  611.                To insert an escape code into  the file,  use control-[
  612.  
  613.           or Alt-27.
  614.  
  615.  
  616.                One feature that VI currently lacks  is the  ability to
  617.  
  618.           change all occurrences of a given string to  another string.
  619.  
  620.           This can  be done  with alternate  uses of  the "n"  and "."
  621.  
  622.           commands (and a little patience).
  623.  
  624.  
  625.  
  626.           ------------------------------------------------------------
  627.  
  628.  
  629.                The above  is a  tutorial introduction  to some  of the
  630.  
  631.           most common VI commands.  A list of all VI  commands appears
  632.  
  633.           in the command summary, below.
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.                                 Command Summary
  662.  
  663.                                 ------- -------
  664.  
  665.  
  666.  
  667.           Colon commands:
  668.  
  669.  
  670.               :w [name]   write to file
  671.  
  672.               :q          quit
  673.  
  674.               :q!         abort
  675.  
  676.               :wq [name]  write and quit
  677.  
  678.               :e name     edit new file
  679.  
  680.               :e! name    discard corrections and edit new file
  681.  
  682.               :f or ^G    print file name, status, and length
  683.  
  684.               :v          print VI version
  685.  
  686.               :r name     read file into current file
  687.  
  688.               :["x]p name put to file
  689.  
  690.  
  691.  
  692.           Character motions:
  693.  
  694.  
  695.               h or Backspace  back one character
  696.  
  697.               Space or Rightarrow   forward one character
  698.  
  699.               ^N or Downarrow   next line, same column
  700.  
  701.               ^P or Uparrow   previous line, same column
  702.  
  703.               $           end of line
  704.  
  705.               0           beginning of line
  706.  
  707.               _           first non-white in line
  708.  
  709.               w           next word
  710.  
  711.               b           back one word
  712.  
  713.               e           end of word
  714.  
  715.               W, B, E     same as w, b, e, with blank-delimited words
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.               %           match (), [], or {}.
  728.  
  729.  
  730.               /string     search
  731.  
  732.               ?string     backwards search
  733.  
  734.               /<cr> or ?<cr> forward or backwards search, same pattern
  735.  
  736.               n           repeat last search
  737.  
  738.               N           repeat last search, opposite direction
  739.  
  740.  
  741.               fx          find next occurrence of x
  742.  
  743.               Fx          find previous x
  744.  
  745.               tx          move up to x
  746.  
  747.               Tx          up to x, backwards
  748.  
  749.               ;           repeat last f, F, t, or T
  750.  
  751.               ,           reverse of ,
  752.  
  753.  
  754.  
  755.           Line motions:
  756.  
  757.  
  758.               + or <cr>   next line (first nonwhite)
  759.  
  760.               -           previous line
  761.  
  762.               H or Home   top of screen
  763.  
  764.               M           middle of screen
  765.  
  766.               L or End    last line of screen
  767.  
  768.               nG          go to nth line (end default)
  769.  
  770.  
  771.  
  772.           Operators:
  773.  
  774.  
  775.               d<motion>, dd, D   delete
  776.  
  777.               c<motion>, cc, C   change
  778.  
  779.               y<motion>, yy, Y   yank
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.           Insert Mode:
  794.  
  795.  
  796.               i or Insert insert before current character
  797.  
  798.               a           insert after current character
  799.  
  800.               I           insert before first nonblank character in line
  801.  
  802.               A           append to end of line
  803.  
  804.               o           open after current line
  805.  
  806.               O           open before current line
  807.  
  808.  
  809.  
  810.           Other modification commands:
  811.  
  812.  
  813.               x or Delete delete character
  814.  
  815.               X           delete previous character
  816.  
  817.               s           delete character and enter insert mode
  818.  
  819.               r           replace character
  820.  
  821.               J           join two lines
  822.  
  823.               p           put yanked text
  824.  
  825.               P           put yanked text before current line or character
  826.  
  827.               u           undo previous command
  828.  
  829.               .           repeat previous command
  830.  
  831.  
  832.  
  833.           Screen commands:
  834.  
  835.  
  836.               ^L          redraw screen
  837.  
  838.               ^F or PgDn  forward one screen
  839.  
  840.               ^B or PgUp  back one screen
  841.  
  842.               ^U, ^D      up (or down) 1/2 screen
  843.  
  844.               z<cr> or zh redraw with current line on top
  845.  
  846.               z<cr> or zm redraw with current line in middle
  847.  
  848.               z<cr> or zl redraw with current line at bottom
  849.